<?php

namespace app\devices\controller;

use app\devices\service\SocketService;
use app\wechat\service\WechatService;
use think\admin\Controller;
use think\admin\Storage;
use think\cache\driver\Redis;
use think\exception\HttpResponseException;
use WeMini\Qrcode;

/**
 * 售后管理
 * Class Index
 * @package app\data\controller
 */
class Sales extends Controller
{

    /**
     * 绑定数据表
     * @var string
     */
    private $table = 'jcg_sales_after';

    protected $status_arr = ['未解决','解决中','已解决'];

    /**
     * 售后管理
     * @auth true
     * @menu true
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function index()
    {
        $this->title = '售后信息管理';
        $map = [];

        $query = $this->_query($this->table);
        $query->where($map)->order('id desc')->equal('status')->dateBetween('create_at')->page();
    }

    /**
     * 列表数据处理
     * @param $data
     */
    public function _index_page_filter(&$data){
        if($data){
            foreach ($data as &$row){
                $row['short'] = mb_substr($row['content'],0,10,'utf-8').'...';
            }
        }
    }

    /**
     * 添加售后信息
     * @auth true
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function add()
    {
        $this->title = '添加售后信息';

        $order_id = input("order_id", 0);
        if($order_id){
            $this->assign("vo", $this->app->db->name("jcg_sales_after")->where("order_id", $order_id)->find());
        }
        $this->_form($this->table, 'form');
    }

    /**
     * 编辑售后信息
     * @auth true
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function edit()
    {
        $this->_form($this->table, 'form');
    }

    /**
     * 数据表单处理
     * @param array $data
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    protected function _form_filter(array &$data)
    {
        if($this->app->request->isPost()){

        }else{

        }
    }

    /**
     * 修改售后信息状态
     * @auth true
     * @throws \think\db\exception\DbException
     */
    public function state()
    {
        $this->_save($this->table, $this->_vali([
            'status.in:1,2'  => '状态值范围异常！',
            'status.require' => '状态值不能为空！',
        ]));
    }

    /**
     * 删除售后信息
     * @auth true
     * @throws \think\db\exception\DbException
     */
    public function remove()
    {
        $this->_delete($this->table);
    }
}


